﻿using System;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Networking")]

namespace CivilRegistry.ControlledModel.Extensions
{
    /// <summary>
    /// Extends the functoinality of system object.
    /// </summary>
    internal static class ObjectExtensions
    {
        /// <summary>
        /// To validate the parameter.
        /// </summary>
        /// <param name="theObject">The object to validate.</param>
        /// <param name="parameterName">The parameter name.</param>
        internal static void Required(this object theObject, string parameterName)
        {
            if (theObject == null)
                throw new ArgumentNullException(parameterName);
        }

        /// <summary>
        /// To validate the ValueType parameter.
        /// </summary>
        /// <param name="theValueTypeObject">The value type object to validate.</param>
        /// <param name="parameterName">The parameter name.</param>
        internal static void Required(this ValueType theValueTypeObject, string parameterName)
        {
            Type theValueTypeObjectType = theValueTypeObject.GetType();

            if(theValueTypeObjectType == typeof(Int16) || theValueTypeObjectType == typeof(Int32) || theValueTypeObjectType == typeof(Int64))
            {
                if((dynamic)theValueTypeObject == 0)
                    throw new ArgumentNullException(parameterName);
            }
            else if (theValueTypeObjectType == typeof(DateTime))
            {
                if ((DateTime)theValueTypeObject == default(DateTime))
                    throw new ArgumentNullException(parameterName);
            }
        }
    }
}
